#include "form_ybhj.h"
#include "ui_form_ybhj.h"
#include "pub_var.h"

#include <QSettings>
#include <QMessageBox>
#include <QDebug>
#include <QSqlError>
#include <QSqlRecord>


Form_ybhj::Form_ybhj(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Form_ybhj)
{
    ui->setupUi(this);
    QSettings setIni("clin.ini", QSettings::IniFormat);
    //恢复当前窗口位置
    QRect rct = setIni.value("windowState/ybhj").toRect();
    this->setGeometry(rct);

    //数据库连接
    qrm = new QSqlQuery(pub::db_m);
    qro = new QSqlQuery(pub::db_o);

    sq = "select hos_name, new_hos_ybbh, new_hos_dzpz_ip, new_hos_dzpz_port,"
         " new_hos_dzpz_tail, new_hos_ybjy_ip, new_hos_ybjy_port, new_hos_ybjy_tail,"
         " new_hos_insuplc, new_hos_secretcode from com_hospitalinfo ";

    qrm->exec(sq);
    qrm->next();
    ui->le_hos_name->setText(qrm->value(0).toString());
    ui->le_new_hos_ybbh->setText(qrm->value(1).toString());
    ui->le_new_hos_dzpz_ip->setText(qrm->value(2).toString());
    ui->le_new_hos_dzpz_port->setText(qrm->value(3).toString());
    ui->le_new_hos_dzpz_tail->setText(qrm->value(4).toString());
    ui->le_new_hos_ybjy_ip->setText(qrm->value(5).toString());
    ui->le_new_hos_ybjy_port->setText(qrm->value(6).toString());
    ui->le_new_hos_ybjy_tail->setText(qrm->value(7).toString());
    ui->le_new_hos_insuplc->setText(qrm->value(8).toString());
    ui->te_new_hos_secretcode->setText(qrm->value(9).toString());
}

Form_ybhj::~Form_ybhj()
{
    delete ui;
}

void Form_ybhj::closeEvent(QCloseEvent *event)
{
    Q_UNUSED(event);
    QSettings setIni("clin.ini", QSettings::IniFormat);
    setIni.setValue("windowState/ybhj", QVariant(this->geometry()));

}

void Form_ybhj::on_pbExit_clicked()
{
    this->close();
}

void Form_ybhj::on_pbSave_clicked()
{

    sq = " update com_hospitalinfo set hos_name = '"
         + ui->le_hos_name->text() + "', new_hos_ybbh = '"
         + ui->le_new_hos_ybbh->text() + "', new_hos_dzpz_ip = '"
         + ui->le_new_hos_dzpz_ip->text() + "', new_hos_dzpz_port = '"
         + ui->le_new_hos_dzpz_port->text() + "', new_hos_dzpz_tail = '"
         + ui->le_new_hos_dzpz_tail->text() + "', new_hos_ybjy_ip = '"
         + ui->le_new_hos_ybjy_ip->text() + "', new_hos_ybjy_port = '"
         + ui->le_new_hos_ybjy_port->text() + "', new_hos_ybjy_tail = '"
         + ui->le_new_hos_ybjy_tail->text() + "', new_hos_insuplc = '"
         + ui->le_new_hos_insuplc->text() + "', new_hos_secretcode = '"
         + ui->te_new_hos_secretcode->toPlainText() + "'";

    qrm->exec(sq);

    QMessageBox::information(this,"注意","配置保存成功！");
}
